package com.jinlejia.erp.ui.house;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.alibaba.fastjson.JSONObject;
import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.FragmentMaintainBinding;
import com.jinlejia.erp.utils.DateUtil;

import org.simple.eventbus.EventBus;
import org.simple.eventbus.Subscriber;

/**
 * 维护信息
 */
public class MaintainFragment extends Fragment {

    JSONObject jsonObject;

    private FragmentMaintainBinding binding;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        EventBus.getDefault().registerSticky(this);
        View view = inflater.inflate(R.layout.fragment_maintain, container, false);
        binding = DataBindingUtil.bind(view);
        EventBus.getDefault().register(this);
        return view;
    }


    @Subscriber(tag = "TAG_HOUSE_DATA")
    public void houseData(JSONObject data) {
        parseData(data);
    }


    @Override
    public void onResume() {
        super.onResume();
//        parseData(jsonObject);
    }

    private void parseData(JSONObject data) {
        binding.sellReason.setText(TextUtils.isEmpty(data.getString("reason")) ? "/" : data.getString("reason"));
        binding.liveState.setText( TextUtils.isEmpty(data.getString("live")) ? "/" : data.getString("live") );
        binding.seeTime.setText(TextUtils.isEmpty(data.getString("seeTime")) ? "/" : data.getString("seeTime"));
        binding.zhuangxiu.setText(TextUtils.isEmpty(data.getString("fit")) ? "/" : data.getString("fit"));
        binding.gongyou.setText(TextUtils.isEmpty(data.getString("isShare")) ? "/" : data.getString("isShare"));
        binding.hukou.setText("/");
        binding.chanquan.setText(TextUtils.isEmpty(data.getString("title")) ? "/" : data.getString("title"));
        binding.yongtu.setText(TextUtils.isEmpty(data.getString("purpose")) ? "/" : data.getString("purpose"));
        binding.houseType.setText(TextUtils.isEmpty(data.getString("housingType")) ? "/" : data.getString("housingType"));
        binding.buildYears.setText(TextUtils.isEmpty(data.getString("buildingYear")) ? "/" : DateUtil.getTime(data.getString("buildingYear"),"yyyy-MM-dd"));
        binding.peiTao.setText(TextUtils.isEmpty(data.getString("assort")) ? "/" : data.getString("assort"));
        binding.wuYeFee.setText(TextUtils.isEmpty(data.getString("fee")) ? "/" : data.getString("fee"));
        binding.jiaJu.setText(TextUtils.isEmpty(data.getString("furniture")) ? "/" : data.getString("furniture"));
        binding.zhengJian.setText(TextUtils.isEmpty(data.getString("idCondition")) ? "/" : data.getString("idCondition"));
        binding.pay.setText(TextUtils.isEmpty(data.getString("payType")) ? "/" : data.getString("payType"));
        binding.jiaDian.setText(TextUtils.isEmpty(data.getString("appliances")) ? "/" : data.getString("appliances"));
        binding.houseTags.setText(TextUtils.isEmpty(data.getString("rsTag")) ? "/" : data.getString("rsTag"));
        binding.cheWei.setText(TextUtils.isEmpty(data.getString("isParking")) ? "/" : data.getString("isParking"));
        binding.cheWeiCount.setText(TextUtils.isEmpty(data.getString("parkingSum")) ? "/" : data.getString("parkingSum"));
        binding.fangChanZhengNo.setText(TextUtils.isEmpty(data.getString("idNumber")) ? "/" : data.getString("idNumber"));
        binding.guoJi.setText(TextUtils.isEmpty(data.getString("nation")) ? "/" : data.getString("nation"));
        binding.houseDes.setText(TextUtils.isEmpty(data.getString("rsRemark")) ? "/" : data.getString("rsRemark"));
    }

}
